{% extends 'InfoCollect/base.html' %}

 {% block title %}
            <title>信息泄露</title>
 {% endblock %}

{% block body %}
<div class="container">
  <div class="jumbotron">
    <h1>信息泄露</h1>
    <div style="padding: 50px 0;">
      <form class="bs-example bs-example-form" role="form">
        <div class="row">
          <div class="col-lg-10">
            <div class="input-group">
              <input id="inputField" type="text" class="form-control" placeholder="请输入网站进行信息泄露扫描，example:https://www.baidu.com/">
              <span class="input-group-btn">
                <button class="btn btn-primary" type="button" onclick="startScan()">Start Scanning</button>
              </span>
            </div>
          </div>
        </div>
      </form>
    </div>
    <p id="scanStatus"></p>
  </div>
</div>
<table class="table">
  <thead id="scanResultHead">
  </thead>
  <tbody id="scanResult">
    <!-- 这里的内容将由JavaScript动态生成 -->
  </tbody>
</table>
    <script>
function startScan() {
    // 清空表格内容
    $('#scanResultHead').empty();
    $('#scanResult').empty();
    $('#scanStatus').text('正在扫描，请稍等...');
    var inputText = $('#inputField').val().trim();
    if(inputText !== '') {
        $.ajax({
            type: "POST",
            url: "{% url 'InfoCollect:infoleak' %}",
            data: {input: inputText},
            success: function(response) {
                console.log('扫描结果：', response);
                if ('scan_result' in response){
                    $('#scanStatus').text('扫描完成');
                    // 显示扫描结果
                    $('#scanResultHead').html('<tr><th>类型</th><th>url</th></tr>');
                    var result = response['scan_result'];
                    $.each(result,function (index,arr) {
                       var title = arr[0];
                       var each_url = arr[1];
                       var row = '<tr><td>' + title + '</td><td>' + '<a href="' + each_url + '">' + each_url + '</a>'+ '</td></tr>';
                       $('#scanResult').append(row);
                    });
                }
            },
            error: function(xhr, status, error) {
                console.error('发生错误：', error);
                alert(error);
            }
        });
    } else {
        alert('请输入要扫描的内容');
    }
}
</script>

{% endblock body %}